package com.ddwl.wallet.dao;

import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.dao.TkDao;
import com.ddwl.schema.bo.wallet.WalletFlowQueryBo;
import com.ddwl.schema.bo.wallet.WalletFlowStatisticsQueryBo;
import com.ddwl.wallet.dao.dto.WalletFlowStatisticsDto;
import com.ddwl.wallet.dao.mapper.UserWalletFlowMapper;
import com.ddwl.wallet.dao.model.UserWalletFlow;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户钱包流水
 */
@Repository
public class UserWalletFlowDao extends TkDao<UserWalletFlowMapper, UserWalletFlow> {



    public List<WalletFlowStatisticsDto> queryPayoffMonthlyReport(WalletFlowStatisticsQueryBo bo){
        return baseMapper.queryMonthlyReport(bo);
    }


    public List<UserWalletFlow> queryWalletFlow(WalletFlowQueryBo bo){
        Example example = getExample();
        example.and().andEqualTo("userId",bo.getUserId())
                .andEqualTo("type",bo.getType())
                .andEqualTo("transactionType",bo.getTransactionType())
                .andGreaterThanOrEqualTo("gmtCreated", bo.getStartTime())
                .andLessThan("gmtCreated",bo.getEndTime());
        return baseMapper.selectByExample(example);
    }

    public List<UserWalletFlow> getWalletFlow(String userId) {
        UserWalletFlow userWalletFlow=new UserWalletFlow();
        userWalletFlow.setUserId(userId);
        userWalletFlow.setDflag(BaseEnum.DflagEnum.NOT_DELETE.getCode());
        List<UserWalletFlow> wallets =  baseMapper.select(userWalletFlow);
        if(CollectionUtils.isEmpty(wallets)){
            return new ArrayList<>(0);
        }
        return wallets;
    }

    public void copyInsert(UserWalletFlow userWalletFlow) {
        baseMapper.insert(userWalletFlow);
    }
}
